package com.ycg.blog.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @author YCG
 * @date 2024-01-21 18:02
 * @description 通用返回结果类
 */
@Data
public class R<T> implements Serializable {

    private Integer code; //编码：1成功，0为失败 2为警告

    private String msg; //错误信息

    private T data; //数据

    public static <T> R<T> success(T object) {
        R<T> r = new R<T>();
        r.msg = "";
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> R<T> error(String msg) {
        R r = new R();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public static <T> R<T> error(String msg, int code) {
        R r = new R();
        r.msg = msg;
        r.code = code;
        return r;
    }

    public static <T> R<T> warning(String msg) {
        R r = new R();
        r.msg = msg;
        r.code = 2;
        return r;
    }



}